//tslint:disable 蜂喔商户端登录组件
import { Component, OnInit, Input } from "@angular/core";
import { FormGroup, FormBuilder, Validators } from "@angular/forms";
import { Router } from "@angular/router";
import { JPush } from "@jiguang-ionic/jpush/ngx";
import { EventService } from "src/app/shared/service/event.service";

import { CustomValidators } from "../../shared/custom-validators/custom-validators";
import { AppGlobalService } from "../../shared/service/app-global.service";
import { HttpService } from "../../shared/service/http.service";
import { ChatService } from "../../shared/service/chatService";
import { IndexedDBService } from "../../shared/service/indexed-db.service";
import { MapBaiduService } from '../../shared/service/map.baiduapi';
import { ViewChild } from '@angular/core';
import { ModalController, Platform } from '@ionic/angular';
import { PageModalService } from "src/app/shared/service/page-modal-service";
import { ShareService } from "src/app/shared/service/share.service";
import { ProcessLoginDataService } from "src/app/shared/service/process-login-data.service";
declare var Fingerprint; // 1.7.0 指纹登录插件
declare var FingerprintAuth; // 1.7.0 安卓端打包兼容用
declare let Wechat: any;
@Component({
  selector: 'app-laijian-login-tag',
  templateUrl: './laijian-login-tag.component.html',
  styleUrls: ['./laijian-login-tag.component.scss'],
})

// TODO 蜂喔赚钱宝登录
export class LaijianLoginTagComponent implements OnInit {
  loginForm: FormGroup;
  open: boolean;
  accountNum = '';
  passwordNum = '';
  messages: any;
  disableBtn = false;
  @ViewChild('accountInput') accountInput;
  @ViewChild('passwordInput') passwordInput;
  @Input() tagData: any = {};
  isCheckRead = false;
  appTypeCustom: any;
  isShowButton = false; // 2023.12.28 是否在特定环境显示微信登录按钮

  mainClassBoxCssStyle: any; // 2024.01.02 新增样式
  ionRowBoxCssStyle: any; // 2024.01.03 ion-row box
  titleBoxCssStyle: any;
  titleFontBoxCssStyle: any;
  ionListBoxCssStyle: any;
  accountBoxCssStyle: any;
  accountInputCssStyle: any;
  passwordNumBoxCssStyle: any;
  passwordNumInputCssStyle: any;
  clearLeftItemBoxCssStyle: any;
  checkBoxDivBoxCssStyle: any;
  enhanceClickBoxCssStyle: any;
  checkiconBoxCssStyle: any;
  uncheckiconBoxCssStyle: any;
  privacyBoxCssStyle: any;
  checkBoxCssStyle: any;
  argumentBoxCssStyle: any;
  privacyPolicyBoxCssStyle: any;
  settleInBoxCssStyle: any;
  submitButtonBoxCssStyle: any;
  submitButtonLabelCssStyle: any;
  bottomBoxCssStyle: any;
  bottomBoxRightCssStyle: any;
  otherLinkLabelCssStyle: any;
  middleLineCssStyle: any;
  forgetNameCssStyle: any;
  rowBottomBoxCssStyle: any;
  tipsCssStyle: any;
  userProtocolCssStyle: any;
  agreementOneLabelCssStyle: any;
  agreementMiddleLineCssStyle: any;
  agreementTwoLabelCssStyle: any;  // 2024.01.02 新增文字样式


  constructor(
    private platform: Platform,
    private eventService: EventService,
    private fb: FormBuilder,
    private http: HttpService,
    public appGlobalService: AppGlobalService,
    private pageModalService: PageModalService,
    private indexedDBService: IndexedDBService,
    private mapBaiduService: MapBaiduService,
    private modalCtrl: ModalController,
    private shareService: ShareService,
    private plService: ProcessLoginDataService,
    private webSocketTalk: ChatService,
    private jPush: JPush,
    public router: Router
  ) {
  }
  ngOnInit() {

    // 2024.01.02
    if (
      this.tagData.data.button.actionElement &&
      this.tagData.data.button.actionElement.param
    ) {

      // 2024.01.03 add for new box cssStyle
      this.tagData.data.button.actionElement.param.map((item, index) => {
        if (item.name === 'mainClassBoxCssStyle') {
          this.mainClassBoxCssStyle = item.value;
        } else if (item.name === 'ionRowBoxCssStyle') {
          this.ionRowBoxCssStyle = item.value;
        } else if (item.name === 'titleBoxCssStyle') {
          this.titleBoxCssStyle = item.value;
        } else if (item.name === 'titleFontBoxCssStyle') {
          this.titleFontBoxCssStyle = item.value;
        } else if (item.name === 'ionListBoxCssStyle') {
          this.ionListBoxCssStyle = item.value;
        } else if (item.name === 'accountBoxCssStyle') {
          this.accountBoxCssStyle = item.value;
        } else if (item.name === 'accountInputCssStyle') {
          this.accountInputCssStyle = item.value;
        } else if (item.name === 'passwordNumBoxCssStyle') {
          this.passwordNumBoxCssStyle = item.value;
        } else if (item.name === 'passwordNumInputCssStyle') {
          this.passwordNumInputCssStyle = item.value;
        } else if (item.name === 'clearLeftItemBoxCssStyle') {
          this.clearLeftItemBoxCssStyle = item.value;
        } else if (item.name === 'checkBoxDivBoxCssStyle') {
          this.checkBoxDivBoxCssStyle = item.value;
        } else if (item.name === 'enhanceClickBoxCssStyle') {
          this.enhanceClickBoxCssStyle = item.value;
        } else if (item.name === 'checkiconBoxCssStyle') {
          this.checkiconBoxCssStyle = item.value;
        } else if (item.name === 'uncheckiconBoxCssStyle') {
          this.uncheckiconBoxCssStyle = item.value;
        } else if (item.name === 'privacyBoxCssStyle') {
          this.privacyBoxCssStyle = item.value;
        } else if (item.name === 'checkBoxCssStyle') {
          this.checkBoxCssStyle = item.value;
        } else if (item.name === 'argumentBoxCssStyle') {
          this.argumentBoxCssStyle = item.value;
        } else if (item.name === 'privacyPolicyBoxCssStyle') {
          this.privacyPolicyBoxCssStyle = item.value;
        } else if (item.name === 'settleInBoxCssStyle') {
          this.settleInBoxCssStyle = item.value;
        } else if (item.name === 'submitButtonBoxCssStyle') {
          this.submitButtonBoxCssStyle = item.value;
        } else if (item.name === 'submitButtonLabelCssStyle') {
          this.submitButtonLabelCssStyle = item.value;
        } else if (item.name === 'bottomBoxCssStyle') {
          this.bottomBoxCssStyle = item.value;
        } else if (item.name === 'bottomBoxRightCssStyle') {
          this.bottomBoxRightCssStyle = item.value;
        } else if (item.name === 'otherLinkLabelCssStyle') {
          this.otherLinkLabelCssStyle = item.value;
        } else if (item.name === 'middleLineCssStyle') {
          this.middleLineCssStyle = item.value;
        } else if (item.name === 'forgetNameCssStyle') {
          this.forgetNameCssStyle = item.value;
        } else if (item.name === 'rowBottomBoxCssStyle') {
          this.rowBottomBoxCssStyle = item.value;
        } else if (item.name === 'tipsCssStyle') {
          this.tipsCssStyle = item.value;
        } else if (item.name === 'userProtocolCssStyle') {
          this.userProtocolCssStyle = item.value;
        } else if (item.name === 'agreementOneLabelCssStyle') {
          this.agreementOneLabelCssStyle = item.value;
        } else if (item.name === 'agreementMiddleLineCssStyle') {
          this.agreementMiddleLineCssStyle = item.value;
        } else if (item.name === 'agreementTwoLabelCssStyle') {
          this.agreementTwoLabelCssStyle = item.value;
        }
      });
    }

    this.appGlobalService.consoleLog('this.platform.ready().then(()1 ', '  	   ');
    // 2023.12.28 是否在特定环境显示微信登录按钮   线上项目预览,测试环境项目预览,apk 则显示按钮 其他情况如H5,不显示
    this.platform.ready().then(() => {
      this.appGlobalService.consoleLog('this.platform.ready().then(()2 ', '  	   ');
      if (!this.platform.is('mobileweb') && (this.platform.is('android') || this.platform.is('ios'))) { // 线上 H5
        this.appGlobalService.consoleLog('this.platform.ready().then(()3 ', '  	   ');
        if ((typeof Wechat) !== 'undefined') {
          // 2024.11.22 新增校验是否有安装微信
          Wechat.isInstalled((installed) => {
            this.appGlobalService.consoleLog(' wechat is ', installed);
            if (!installed || installed === 0) { // 安卓wechat插件installed返回值 0,1
              this.isShowButton = false;
            } else {
              this.isShowButton = true;
            }
          }, (reason) => {
            this.isShowButton = false;
            this.appGlobalService.consoleLog('wechat is notInstall', reason);
            this.appGlobalService.showToast("您没有安装微信", 2000, "top");
          });
        } else {
          this.appGlobalService.consoleLog('this.platform.ready().then(()4 ', '  	   ');
        }
      } else {
        this.appGlobalService.consoleLog(' checkIsApp = false', '  	   ');
      }
    });
    localStorage.setItem('loginStatus', 'false');
    const that = this;
    const bodyStyles = window.getComputedStyle(document.body);
    this.appTypeCustom = bodyStyles.getPropertyValue('--appTypeCustom').trim().replace('"', '').replace('"', '');
    console.log("msg----->entrance login" + new Date().toLocaleDateString());
    if (this.tagData.data.agreement[2] && this.tagData.data.agreement[2].label.link.target) {
      // this.appGlobalService.reportPageId = this.tagData.data.agreement[2].label.link.target;
      localStorage.setItem('reportPageId', this.tagData.data.agreement[2].label.link.target);
    }


    // 2023年6月15日 蜂喔商户端，新增弹窗提示用户使用权限申明
    if (this.tagData.data.otherLink1) {
      this.appGlobalService.privateRightPageLink = { link: this.tagData.data.otherLink1 };
    }

    let mobile =
      localStorage.getItem("loginAccount") &&
        localStorage.getItem("loginAccount") !== "undefined"
        ? localStorage.getItem("loginAccount")
        : "";
    if (mobile && mobile.length > 11) {
      mobile = '';
    }
    this.loginForm = this.fb.group({
      account: [mobile, [Validators.required, CustomValidators.phone]],
      password: [
        "",
        [
          Validators.required,
          Validators.minLength(6),
          Validators.maxLength(30)
        ]
      ]
    });
    this.accountNum = mobile;
    // TODO enableFingerPrint 为 -1 不校验指纹或者指纹校验失败
    // TODO enableFingerPrint 为 null  第一次弹窗
    // TODO enableFingerPrint 为 1  指纹验证通过 并且开启 第一次已经开启过
    // TODO enableFingerPrint 为 2  已经开启过然后正常退出到首页第二次指纹登录时弹出
    if (localStorage.getItem('enableFingerPrint') !== null && localStorage.getItem('enableFingerPrint') === '2') {
      setTimeout(() => {
        // 蜂喔商户 1.6.19.1 新增属性 perfectLink
        if (this.tagData.data.perfectLink !== undefined) {
          this.tagData.data.perfectLink.params.hiddenButton = 1;
          this.tagData.data.perfectLink.params.mobile = localStorage.getItem('loginAccount');

          if (localStorage.getItem('platform') === 'ios') {  // ios
            if ((typeof Fingerprint) !== 'undefined') {
              Fingerprint.isAvailable((successResult) => {
                console.log("isAvailable:", successResult);
                if (successResult && successResult !== 'face') {
                  this.pageModalService.openPage(this.tagData.data.perfectLink, (result) => {
                  });
                }

              }, (errorResult) => {
                console.log('您的设备不支持指纹！');
              }, {});
            }

          } else if (localStorage.getItem('platform') === 'android') { // android
            if ((typeof FingerprintAuth) !== 'undefined') {
              FingerprintAuth.isAvailable((successResult) => {
                // console.log('isAvailable:' + successResult);
                if (successResult.isAvailable) {
                  this.pageModalService.openPage(this.tagData.data.perfectLink, (result) => {
                  });
                }
              }, (errorResult) => {
                console.log('您的设备不支持指纹！');
              }, {});
            }
          } else { // 项目预览
            this.pageModalService.openPage(this.tagData.data.perfectLink, (result) => {
            });
          }
        }
      }, 50);
    }

    // 指纹登录submitId
    if (this.tagData.data.fingerprintBut !== undefined) {
      this.appGlobalService.fingerPrintSubmitId = this.tagData.data.fingerprintBut.id;
      this.appGlobalService.fingerPrintParams = this.tagData.data.fingerprintBut.actionElement.param;
    }

    this.platform.ready().then(() => {
      // 2024.01.14 触发定位
      this.eventService.eventEmit.emit("refreshLocationStoreForAndroid", '1');
      // tslint:disable-next-line:no-string-literal
      if (window['MobileAccessibility'] !== undefined) {
        // tslint:disable-next-line:no-string-literal
        window['MobileAccessibility'].usePreferredTextZoom(false);
      }
    });
  }
  changePwd() {
    const forget = this.tagData.data.forget;
    const params = {
      pageId: forget.link.target,
      params: forget.link.params,
      sessionId: localStorage.getItem("sessionId")
    };
    localStorage.setItem("loginAccount", this.loginForm.value.account);
    this.appGlobalService.goToForward(params);
  }

  getErrors() {
    if (this.loginForm.controls.account.errors) {
      if (this.loginForm.controls.account.errors.required) {
        this.appGlobalService.showToast("请输入手机号码", 3000, "top");
      } else {
        this.appGlobalService.showToast("请输入正确的手机号码", 3000, "top");
      }
    } else if (this.loginForm.controls.password.errors) {
      if (this.loginForm.controls.password.errors.required) {
        this.appGlobalService.showToast("请输入密码", 3000, "top");
      } else {
        this.appGlobalService.showToast("请输入正确的密码", 3000, "top");
      }
    }
  }
  submitForm(): void {
    if (this.isCheckRead === false) {
      this.appGlobalService.showToast('请先同意用户协议及隐私政策再继续使用APP', 2000, 'top');
      return;
    }
    if (this.loginForm.status === "INVALID") {
      this.getErrors();
      return;
    }
    this.disableBtn = true;
    this.loginForm.value.device_model = this.getDeviceModel();
    const obj = {
      account: this.loginForm.value.account,
      password: this.appGlobalService.encryptDes(this.loginForm.value.password),
      device_model: this.getDeviceModel()
    };

    // 2024.09.19 huawei
    if (localStorage.getItem('huawei')) {
      Object.assign(obj, { amobile: 'huawei' });
    }

    // 2023.11.24 getUuid
    Object.assign(obj, { imei: this.eventService.getUuid(), clientType: this.appGlobalService.clientType });

    if (localStorage.getItem("isDetailPage")) {
      obj['skip'] = 0;
    }

    if (localStorage.getItem("wxloginOpenID")) {
      obj['openid'] = localStorage.getItem("wxloginOpenID");
    }

    const params = {
      content: obj,
      id: this.tagData.data.button.id,
      sessionId: localStorage.getItem("sessionId")
    };
    if (
      this.tagData.data.button.actionElement &&
      this.tagData.data.button.actionElement.param
    ) {
      const excludedNames = [
        'mainClassBoxCssStyle',
        'ionRowBoxCssStyle',
        'titleBoxCssStyle',
        'titleFontBoxCssStyle',
        'ionListBoxCssStyle',
        'accountBoxCssStyle',
        'accountInputCssStyle',
        'passwordNumBoxCssStyle',
        'passwordNumInputCssStyle',
        'clearLeftItemBoxCssStyle',
        'checkBoxDivBoxCssStyle',
        'enhanceClickBoxCssStyle',
        'checkiconBoxCssStyle',
        'uncheckiconBoxCssStyle',
        'privacyBoxCssStyle',
        'checkBoxCssStyle',
        'argumentBoxCssStyle',
        'privacyPolicyBoxCssStyle',
        'settleInBoxCssStyle',
        'submitButtonBoxCssStyle',
        'submitButtonLabelCssStyle',
        'bottomBoxCssStyle',
        'bottomBoxRightCssStyle',
        'otherLinkLabelCssStyle',
        'middleLineCssStyle',
        'forgetNameCssStyle',
        'rowBottomBoxCssStyle',
        'tipsCssStyle',
        'userProtocolCssStyle',
        'agreementOneLabelCssStyle',
        'agreementMiddleLineCssStyle',
        'agreementTwoLabelCssStyle'
      ];

      this.tagData.data.button.actionElement.param.map(item => {
        if (!excludedNames.includes(item.name)) {
          params.content[item.name] = item.value;
        }
      });
    }
    const that = this;
    this.http.post("application/submit", params, res => {
      if (res.success) {
        if (params.content.password && params.content.password.length > 0) {
          const alp = this.appGlobalService.encryptALP(params.content.password);
          localStorage.setItem('ALP', alp);
        }
        if (res.data.position) {
          if (res.data.position.districtCode === undefined) {
            // tslint:disable-next-line:no-string-literal
            res.data.position['districtCode'] = this.appGlobalService.defaultDistrictCode;
          }
          this.setPxwCityPosition(res.data.position);
        }
        if (res.data.user_id) {
          localStorage.setItem("userId", res.data.user_id);
          localStorage.setItem("loginAccount", this.loginForm.value.account);
          localStorage.setItem("fingerPrintSubmitMobile", this.loginForm.value.account);
          this.appGlobalService.initUmengEventWithParameters("enter_app_with_loginAccount_event");
          that.jPush
            .setAlias({
              sequence: 1,
              alias: this.appGlobalService.pushAlias + params.content.account
            })
            .then(
              result => {
                const sequence = result.sequence;
                const alias = result.alias;
                console.log("设置别名成功：" + alias);
              },
              error => {
                const sequence = error.sequence;
                const errorCode = error.code;
                console.log("设置别名失败：" + errorCode);
              }
            );



          this.http.get(
            "message/userinfo/im/" + res.data.user_id,
            response => {
              const data = response.data;
              if (data) {
                if (res.data.user_id.includes('random')) {
                  data.nickname = '访客';
                }
                if (data.nickname) {
                  this.appGlobalService.currentNickName = data.nickname;
                  localStorage.setItem('currentNickName', data.nickname);
                }
                if (data.avatar_url === null) { // 没头像给默认头像
                  data.avatar_url = this.appGlobalService.defaultImg;
                }
                if (data.avatar_url) {
                  this.appGlobalService.getBase64Str(data.avatar_url + "?x-oss-process=image/resize,h_36", str => {
                    localStorage.setItem('currentAvatarStr', str);
                    that.webSocketTalk.setAvatar(res.data.user_id, str);
                  });
                  this.appGlobalService.currentAvatarUrl = data.avatar_url;
                  localStorage.setItem('currentAvatarUrl', data.avatar_url);
                }
                localStorage.setItem('currentWorkMobile', data.work_mobile);
                // 2024.08.02 联调接口返回参数
                if (res.data.shopGoodsCartCount) {
                  // tslint:disable-next-line:no-string-literal
                  data['shopGoodsCartCount'] = res.data.shopGoodsCartCount;
                }
                that.webSocketTalk.currentUserObj = data;
                this.indexedDBService.putByKeyCallbak(data, res.data.user_id, "user", () => {
                  if (res.data.shopGoodsCartCount) {
                    that.webSocketTalk.setCartItemCount(res.data.shopGoodsCartCount);
                  }
                });
              }
            },
            error => {
              console.log("msg-----> error:" + JSON.stringify(error));
            }
          );

          // 2023.12.01 websocket链接
          this.webSocketTalk.connectting(this.loginForm.value.account, true, (eData) => {
            // console.log(new Date().toLocaleString() + '.' + new Date().getMilliseconds() + '  ws.connectting   ', eData);
          });


          // 2024.07.09 初始化临时全局变量
          that.appGlobalService.initTemporaryVariables();

          if (this.appGlobalService.clientType === 'js') {
            localStorage.setItem('startRefreshTimerTag', '1');
            this.eventService.eventEmit.emit("startRefreshTimer");
          }
        }
        localStorage.setItem("loginStatus", "true");
        this.appGlobalService.loginStatus = true;
        localStorage.setItem("needRefreshTab1", "true");
        localStorage.setItem("needRefreshTab2", "true");
        localStorage.setItem("needRefreshTab3", "true");
        localStorage.setItem("needRefreshTab4", "true");
        localStorage.setItem("needRefreshTab5", "true");
        if (res.data && res.data.badge) {
          res.data.badge.forEach(element => {
            const key = Object.keys(element)[0];
            if (Number(element[key]) >= 0) {
              console.log("msg----->" + Number(element[key]));
              this.eventService.eventEmit.emit("firstBadgeForTab", {
                [key]: Number(element[key])
              });
            }
          });
        }
        if (localStorage.getItem('enableFingerPrint') === null || localStorage.getItem('enableFingerPrint') === undefined) {
          localStorage.setItem('showCenterFirstBtnLabel', 'false');
          setTimeout(() => {
            // 蜂喔商户 1.6.15 未认证不跳转到successLink
            if (this.tagData.data.successLink !== undefined && res.data.user_id) {
              if (localStorage.getItem('platform') === 'ios') { // ios
                if ((typeof Fingerprint) !== 'undefined') {
                  Fingerprint.isAvailable((successResult) => {
                    console.log("isAvailable:", successResult);
                    if (successResult && successResult !== 'face') {
                      this.pageModalService.openPage(this.tagData.data.successLink);
                    }
                  }, (errorResult) => {
                    console.log('您的设备不支持指纹！');
                  }, {});
                } else {
                  this.pageModalService.openPage(this.tagData.data.successLink);
                }
              } else if (localStorage.getItem('platform') === 'android') { // android
                if ((typeof FingerprintAuth) !== 'undefined') {
                  FingerprintAuth.isAvailable((successResult) => {
                    // console.log('isAvailable:' + successResult);
                    if (successResult.isAvailable) {
                      this.pageModalService.openPage(this.tagData.data.successLink);
                    }
                  }, (errorResult) => {
                    console.log('您的设备不支持指纹！');
                  }, {});
                } else {
                  this.pageModalService.openPage(this.tagData.data.successLink);
                }
              } else { // 项目预览
                this.pageModalService.openPage(this.tagData.data.successLink);
              }
            }
          }, 1500);
        }
        // // todo 第一次打开app查看是否可用指纹登录
        if (localStorage.getItem("useTarget") === "true") {
          const cityId = JSON.parse(localStorage.getItem("position"))
            ? JSON.parse(localStorage.getItem("position")).code
            : 4403;
          const pageParams = {
            pageId: res.target,
            params: {
              code: cityId
            },
            sessionId: localStorage.getItem("sessionId")
          };
          this.appGlobalService.goToForward(pageParams);
          localStorage.removeItem("useTarget");
        } else {
          const skip = res.skip;
          if (skip && skip === 1) {
            const pageParams = {
              pageId: res.target,
              params: res.params,
              sessionId: localStorage.getItem("sessionId")
            };
            this.appGlobalService.goToForward(pageParams);
          } else if (localStorage.getItem("isDetailPage") && skip === 0) {
            localStorage.setItem("needRefresh", "true");
            this.appGlobalService.popTarget();
            this.appGlobalService.goBack();
          } else if (skip === 0) {
            const pageParams = {
              pageId: res.target,
              params: res.params,
              sessionId: localStorage.getItem("sessionId")
            };
            if (JSON.parse(localStorage.getItem("appNav"))) {
              this.appGlobalService.goToForward(pageParams);
            } else {
              this.appGlobalService.goToForward(pageParams);
              this.appGlobalService.goBack()
              setTimeout(() => {
                window.location.reload();
              }, 100);

            }


          } else {
            localStorage.setItem("needRefresh", "true");
            this.appGlobalService.goBack();
          }
        }
      } else {
        this.appGlobalService.showToast(res.message, 1500, "middle");
      }
      this.disableBtn = false;
    });
  }
  editStyle() {
  }
  checkTime(i) {
    if (Number(i) < 10) {
      i = "0" + i;
    }
    return i;
  }
  async isYestday(theDate) {
    return (await new Date().getDate()) - theDate.getDate() === 1;
  }
  isSameWeek(old, now) {
    const oneDayTime = 1000 * 60 * 60 * 24;
    // tslint:disable-next-line:radix
    const oldCount = parseInt(old.getTime() / oneDayTime + "");
    // tslint:disable-next-line:radix
    const nowOther = parseInt(now.getTime() / oneDayTime + "");
    return (
      // tslint:disable-next-line:radix
      parseInt((oldCount + 4) / 7 + "") === parseInt((nowOther + 4) / 7 + "")
    );
  }
  getTime() {
    // tslint:disable-next-line:radix
    const m = parseInt(new Date().getMinutes() + "");
    // tslint:disable-next-line:radix
    return parseInt(new Date().getHours() + "") + ":" + (m < 10 ? "0" + m : m);
  }
  getDeviceModel() {
    return localStorage.getItem("device");
  }
  setPxwCityPosition(positionInfo) {
    if (this.appGlobalService.clientType === 'pxw') {
      const firstPostion = localStorage.getItem('firstPostion');
      if (!firstPostion) {
        localStorage.setItem('firstPostion', JSON.stringify(positionInfo));
        localStorage.setItem('position', JSON.stringify(positionInfo));
      }
    } else if (this.appGlobalService.clientType === 'js') {
      localStorage.setItem('position', JSON.stringify(positionInfo));
    }
    this.mapBaiduService.getPointByName(positionInfo.name, (point) => {
      positionInfo.center = { lng: point.lng, lat: point.lat };
      localStorage.setItem('position', JSON.stringify(positionInfo));
    });
  }
  focusInput(type) {
    if (type === '1') {
      this.accountInput.setFocus();
    } else if (type === '2') {
      this.passwordInput.setFocus();
    }
  }
  newShop() {
    if (this.tagData.data.register && this.tagData.data.register.link) {
      const sessionId = localStorage.getItem("sessionId");
      if (this.tagData.data.register.link.params && this.tagData.data.register.link.params.path) {

        const navigateUrl = this.tagData.data.register.link.params.path;
        localStorage.setItem('backToLaiJianLogin', 'true');
        this.router.navigate([navigateUrl], { queryParams: { item: JSON.stringify(this.tagData.data.register.link) } });
      } else {
        const pageParams = {
          pageId: this.tagData.data.register.link.target,
          params: this.tagData.data.register.link.params,
          sessionId,
        };
        // this.appGlobalService.goToForward(pageParams);
        this.pageModalService.openPage(this.tagData.data.register.link);
      }
    }
  }
  async openArgument(e) {
    e.stopPropagation();
    this.eventService.eventEmit.emit("openPage",
      // tslint:disable-next-line:no-string-literal
      JSON.stringify({ type: 'url', urlLinkTitle: "用户协议", target: window['appGlobalService'].serviceAgreementLink, params: {} }));
  }
  async alertPrivacyPolicy(e) {
    e.stopPropagation();
    this.eventService.eventEmit.emit("openPage",
      // tslint:disable-next-line:no-string-literal
      JSON.stringify({ type: 'url', urlLinkTitle: "隐私政策", target: window['appGlobalService'].privatePolicyLink, params: {} }));
  }
  checkRead() {
    this.isCheckRead = !this.isCheckRead;
  }

  wxAuth() {
    // 2024.01.24 微信登录也要勾选隐私协议
    if (this.isCheckRead === false) {
      this.appGlobalService.showToast('请先同意用户协议及隐私政策再继续使用APP', 2000, 'top');
      return;
    }
    this.pageModalService.wxAuth(this.tagData);
  }

  openPage(link) {
    this.pageModalService.openPage(link);
  }

  openSettleIn(e) {
    e.stopPropagation();
    const link = {
      type: 'url',
      urlLinkTitle: "入驻协议",
      target: this.appGlobalService.settleInLink,
    };
    this.pageModalService.openPage(link);
  }
}
